/**
 * @file convert.h
 * @author your name (you@domain.com)
 * @brief 位逻辑指令
 * @version 0.1
 * @date 2025-04-30
 *
 * @copyright Copyright (c) 2025
 *
 */
// convert.h
#ifndef CONVERT_H
#define CONVERT_H

#include "xmzTypeDefine.h"
#include <stdbool.h>
#include <stdint.h>

typedef enum {
  TYPE_BYTE,
  TYPE_WORD,
  TYPE_DWORD,
  TYPE_LWORD,
  TYPE_SINT,
  TYPE_USINT,
  TYPE_INT,
  TYPE_UINT,
  TYPE_DINT,
  TYPE_UDINT,
  TYPE_LINT,
  TYPE_ULINT,
  TYPE_REAL,
  TYPE_LREAL,
  TYPE_CHAR,
  TYPE_WCHAR,
	TYPE_BOOL,
	TYPE_TIME,
  TYPE_COUNT // n=18
} DataType;
Bool convert(Bool en, DataType inType, void* in, DataType outType, void* out);
// 宏：生成单个函数声明
#define DECLARE_CONVERT_FUNC(out_type, in_type, out_type_t, in_type_t) out_type_t in_type##_TO_##out_type(in_type_t in);

// 宏：为单一输入类型生成 16 个函数声明
#define DECLARE_CONVERTERS_FOR_INPUT(in_type, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(BYTE, in_type, Byte, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(WORD, in_type, Word, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(DWORD, in_type, DWord, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(LWORD, in_type, LWord, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(SINT, in_type, SInt, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(USINT, in_type, USInt, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(INT, in_type, Int, in_type_t)                                                                   \
  DECLARE_CONVERT_FUNC(UINT, in_type, UInt, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(DINT, in_type, DInt, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(UDINT, in_type, UDInt, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(LINT, in_type, LInt, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(ULINT, in_type, ULInt, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(REAL, in_type, Real, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(LREAL, in_type, LReal, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(CHAR, in_type, Char, in_type_t)                                                                 \
  DECLARE_CONVERT_FUNC(WCHAR, in_type, WChar, in_type_t)                                                               \
  DECLARE_CONVERT_FUNC(BOOL, in_type, Bool, in_type_t)                                                                  \
	DECLARE_CONVERT_FUNC(TIME, in_type, Time, in_type_t)                                                                                                                   

// 生成所有 256 个函数声明
DECLARE_CONVERTERS_FOR_INPUT(BYTE, Byte)
DECLARE_CONVERTERS_FOR_INPUT(WORD, Word)
DECLARE_CONVERTERS_FOR_INPUT(DWORD, DWord)
DECLARE_CONVERTERS_FOR_INPUT(LWORD, LWord)
DECLARE_CONVERTERS_FOR_INPUT(SINT, SInt)
DECLARE_CONVERTERS_FOR_INPUT(USINT, USInt)
DECLARE_CONVERTERS_FOR_INPUT(INT, Int)
DECLARE_CONVERTERS_FOR_INPUT(UINT, UInt)
DECLARE_CONVERTERS_FOR_INPUT(DINT, DInt)
DECLARE_CONVERTERS_FOR_INPUT(UDINT, UDInt)
DECLARE_CONVERTERS_FOR_INPUT(LINT, LInt)
DECLARE_CONVERTERS_FOR_INPUT(ULINT, ULInt)
DECLARE_CONVERTERS_FOR_INPUT(REAL, Real)
DECLARE_CONVERTERS_FOR_INPUT(LREAL, LReal)
DECLARE_CONVERTERS_FOR_INPUT(CHAR, Char)
DECLARE_CONVERTERS_FOR_INPUT(WCHAR, WChar)
DECLARE_CONVERTERS_FOR_INPUT(BOOL, Bool)
DECLARE_CONVERTERS_FOR_INPUT(TIME, Time)



typedef enum {
  IN_TYPE_REAL,
  IN_TYPE_LREAL,
	IN_TYPE_COUNT
} InputType;

typedef enum {
  OUT_TYPE_INT,
  OUT_TYPE_SINT,
  OUT_TYPE_DINT,
  OUT_TYPE_UINT,
  OUT_TYPE_USINT,
  OUT_TYPE_UDINT,
  OUT_TYPE_LREAL,
  OUT_TYPE_REAL,
	OUT_TYPE_COUNT
} OutputType;
Bool Round(Bool en, InputType in_type, const void* in, OutputType out_type, void* out);

Bool Ceil(Bool en, InputType in_type, const void* in, OutputType out_type, void* out);
Bool Floor(Bool en, InputType in_type, const void* in, OutputType out_type, void* out);
#endif
